package com.xtpt.disaster.service.impl;

import com.xtpt.disaster.bean.BackupFileInfo;
import com.xtpt.disaster.mapper.BackupFileInfoMapper;
import com.xtpt.disaster.service.BackupFileInfoManageService;
import com.xtpt.disaster.utils.IDGenerator;
import com.xtpt.disaster.utils.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class BackupFileManageServiceImpl implements BackupFileInfoManageService {
    @Autowired
    BackupFileInfoMapper backupFileInfoMapper;

    @Override
    public int insertBackupInfo(BackupFileInfo backupFileInfo) {
        Long id = IDGenerator.longid();
        Date createTime = TimeUtil.dateMaker();
        Date updateTime = TimeUtil.dateMaker();
        backupFileInfo.setBpfId(id);
        backupFileInfo.setCreateTime(createTime);
        backupFileInfo.setUpdateTime(updateTime);
        return backupFileInfoMapper.insert(backupFileInfo);
    }

    @Override
    public int insertBackupInfoSelective(BackupFileInfo backupFileInfo) {
        Long id = IDGenerator.longid();
        Date createTime = TimeUtil.dateMaker();
        Date updateTime = TimeUtil.dateMaker();
        backupFileInfo.setBpfId(id);
        backupFileInfo.setCreateTime(createTime);
        backupFileInfo.setUpdateTime(updateTime);
        return backupFileInfoMapper.insert(backupFileInfo);
    }

    @Override
    public BackupFileInfo selectBackupFileById(Long id) {
        return backupFileInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateBackupFileById(BackupFileInfo backupFileInfo) {
        Date updateTime = TimeUtil.dateMaker();
        backupFileInfo.setUpdateTime(updateTime);
        return backupFileInfoMapper.updateByPrimaryKey(backupFileInfo);
    }

    @Override
    public int updateBackupFileByIdSelective(BackupFileInfo backupFileInfo) {
        return backupFileInfoMapper.updateByPrimaryKey(backupFileInfo);
    }

    @Override
    public int deleteById(Long id) {
        return backupFileInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteBatch(long[] ids) {
        return backupFileInfoMapper.deleteBatch(ids);
    }

    @Override
    public List<BackupFileInfo> getAllBackupFileInfo() {
        return backupFileInfoMapper.selectAll();
    }


}
